"""
 -*- coding: utf-8-*-
 @File: mgt_schema.py
 @Author: chen
 @time: 2023/10/25/ 19:54
"""
from genson import SchemaBuilder
from jsonschema.validators import validate

from hogwartsHomework.homework_api_auto.utils.util_log import logger


def build_jsonschema(json_obj: dict):
    """生成对应的schema数据"""
    builder = SchemaBuilder()
    builder.add_object(json_obj)
    return builder.to_schema()


def validate_schema(data_obj, schema):
    """验证schema数据"""
    # validate(data_obj, schema)
    try:
        validate(data_obj, schema)
        return True
    except Exception as e:
        logger.info(f"验证失败，异常信息：{e}")
        return False
